// import useSystemControl from "@/composables/useSystem";

export default function getCookieValue(cookieName: string) {
    const cookieString = document.cookie;
    // 将cookie字符串拆分成多个键值对
    const cookieArray = cookieString.split('; ');
    // 遍历键值对数组，找到匹配的cookie
    for (let i = 0; i < cookieArray.length; i++) {
        const cookiePair = cookieArray[i].split('=');
        // 去除空格并判断cookie名称是否匹配
        if (cookiePair[0].trim() === cookieName) {
            return cookiePair[1];
        }
    }
    // 若未找到匹配的cookie，则返回null或者其他你认为适合的默认值
    return null;
}

export const  clearCookies = () => {
    const cookieString = document.cookie;
    // const useSystem = useSystemControl()
    // 将cookie字符串拆分成多个键值对
    const cookieArray = cookieString.split('; ');
    // 遍历键值对数组，找到匹配的cookie
    for (let i = 0; i < cookieArray.length; i++) {
        const cookiePair = cookieArray[i].split('=');
        const date = new Date();
        date.setTime(date.getTime() - (24 * 60 * 60 * 1000)); // 设置时间为24小时前
        const expires = "expires=" + date.toUTCString();
        document.cookie = `${cookiePair[0].trim()}=; ` + expires + "; path=/"; // 将cookie_name设置为已经过去的时间
    }
    // useSystem.Authorization.value = ''
}
